package myJs.api

import myJs.myPkg.MyFetch
import myJs.tool.Tool
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.pojo.Pojo
import shared.pojo.Pojo.ValidData
import shared.pojo.Sample.IdStrsData
import upickle.default._

/**
 * Created by yz on 19/5/2022
 */
object FreezerSetApi {

  import Pojo.freezerSet._

  val baseUrl = s"${Api.apiUrl}/panda/freezerSet"
  val adminUrl = s"${Api.apiUrl}/panda/admin/freezerSet"

  def update(request: FreezerSetData) = {
    val url = s"${adminUrl}/insertOrUpdate"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json",
      "X-Authorization" -> s"Bearer ${Tool.getToken}")).map { str =>
      str
    }
  }

  def get(request: FreezerSetData) = {
    val url = s"${baseUrl}/get"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json",
      "X-Authorization" -> s"Bearer ${Tool.getToken}")).map { str =>
      read[Option[FreezerSetData]](str)
    }
  }


}
